//
// Copyright (c) 2023-2023 the rbfx project.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#include <Urho3D/Core/Context.h>
#include <Urho3D/Scene/Node.h>
#include <Urho3D/Input/MoveAndOrbitComponent.h>

namespace Urho3D
{

MoveAndOrbitComponent::MoveAndOrbitComponent(Context* context)
    : BaseClassName(context)
{

}

void MoveAndOrbitComponent::RegisterObject(Context* context)
{
    context->AddFactoryReflection<MoveAndOrbitComponent>(Category_Logic);
}

void MoveAndOrbitComponent::OnNodeSet(Node* previousNode, Node* currentNode)
{
    if (currentNode)
    {
        const Quaternion& currentRotation = currentNode->GetRotation();
        SetYaw(currentRotation.YawAngle());
        SetPitch(currentRotation.PitchAngle());
    }
}

void MoveAndOrbitComponent::SetVelocity(const Vector3& velocity)
{
    velocity_ = velocity;
}

void MoveAndOrbitComponent::SetYaw(float yaw)
{
    yaw_ = yaw;
}

void MoveAndOrbitComponent::SetPitch(float pitch)
{
    pitch_ = Clamp(pitch, -90.0f, 90.0f);
}

void MoveAndOrbitComponent::SetDistanceLimits(float minDistance, float maxDistance)
{
    minDistance_ = minDistance;
    maxDistance_ = maxDistance;
}

} // namespace Urho3D
